package com.pet.system.controller;

import com.github.pagehelper.PageInfo;
import com.pet.system.common.AjaxResult;
import com.pet.system.common.BaseController;
import com.pet.system.controller.vo.PetVo;
import com.pet.system.entity.Pet;
import com.pet.system.service.PetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/pet")
@Api(value = "宠物")
public class PetController extends BaseController {
    @Autowired
    private PetService petService;

    @GetMapping("/list")
    @ApiOperation("分页")
    public AjaxResult list(PetVo pet) {
        PageInfo<Pet> result = petService.getPageList(pet);
        return AjaxResult.success(result);
    }

    @GetMapping(value = {"/{id}"})
    @ApiOperation("详情")
    public AjaxResult getInfo(@PathVariable(value = "id", required = false) Long id) {
        Pet pet= petService.getInfo(id);
        return AjaxResult.success(pet);
    }

    @PostMapping
    @ApiOperation("添加")
    public AjaxResult add(@Validated @RequestBody Pet pet) {

        return toAjax(petService.add(pet));
    }

    @PutMapping
    @ApiOperation("修改")
    public AjaxResult edit(@Validated @RequestBody Pet pet) {

        return toAjax(petService.edit(pet));
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("批量删除")
    public AjaxResult remove(@PathVariable Long[] ids) {

        return toAjax(petService.remove(ids));
    }
}
